package app.kotlin_1.view

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent

/**
 * Created by 刘智强 on 2017/9/26.
 */
class MyRecyclerView : RecyclerView {

    private var downX: Float = 0f
    private var downY: Float = 0f

    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)


    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        parent.requestDisallowInterceptTouchEvent(true)
        return super.dispatchTouchEvent(ev)
    }

    override fun onTouchEvent(ev: MotionEvent?): Boolean {

        when (ev?.action) {
            MotionEvent.ACTION_MOVE -> {
                if (!canScrollVertically(-1)) {
                    Log.e("111", "到顶部了")
                    parent.requestDisallowInterceptTouchEvent(false)
                } else {
                    parent.requestDisallowInterceptTouchEvent(true)
                }
            }
        }
        return super.onTouchEvent(ev)

    }
//    override fun onInterceptTouchEvent(e: MotionEvent?): Boolean {
//
//        var intercept: Boolean = false
//        var x = e?.x
//        var y = e?.y
//        when (e?.action) {
//            MotionEvent.ACTION_DOWN -> {
//                parent.requestDisallowInterceptTouchEvent(true)
//            }
//            MotionEvent.ACTION_MOVE -> {
//                if (!canScrollVertically(-1)) {
//                    parent.requestDisallowInterceptTouchEvent(false)}
////                } else {
////                    parent.requestDisallowInterceptTouchEvent(true)
////                }
//
//            }
//        }
//
//
//        return super.onInterceptTouchEvent(e)
//    }

}